
import java.util.Random;

import javax.microedition.lcdui.Graphics;

/**
 * 
 * @author hanying zheng
 *
 */
public class BallLv2 {

	private final static Random random = new Random();
	
	public int x;
	
	public int y;
	
	/**
	 * radius
	 */
	public final int r;
	
	private int r1;
	
	public final int d;
	
	private int d1;
	
	public int dx;
	
	public int dy;
	
	private int ddx = 0;
	
	private int ddy = 0;

	public BallLv2(int x, int y, int dx, int dy, int screenWidth) {
		this.x = x;
		this.y = y;
		this.dx = dx;
		this.dy = dy;
		//this.r = screenWidth / 30;
		this.r = 5;
		d = r * 2;
		r1 = r - 1;
		d1 = d - 2;
	}
	
	public final void move() {
		x += dx + ddx;
		y += dy + ddy;
	}
	
	public final void hitHorizontally() {
		dy = -dy;
		
		int rand = random.nextInt(100);
		if (rand < 10) {
			ddy = -1;
		} else if (rand < 20) {
			ddy = 1;
		} else {
			ddy = 0;
		}
		
		y += dy << 1;
	}
	
	public final void hitVertically() {
		dx = -dx;
		
		int rand = random.nextInt(100);
		if (rand < 10) {
			ddx = -1;
		} else if (rand < 20) {
			ddx = 1;
		} else {
			ddx = 0;
		}
		
		x += dx << 1;
	}
	
	public void paint(Graphics g) {
		g.setColor(0, 0, 0);
        g.fillArc(x + 2 - r, y + 2 - r, d, d, 0, 360);
        g.setColor(255, 0, 0);
        g.fillArc(x - r, y - r, d, d, 0, 360);

        g.setColor(245, 0, 0);
        g.fillArc(x - r1, y - r1, d1, d1, 0, 360);
        
    }
}

